<template>
    <div id="app">
      <template v-if="$route.path == '/'">
        <ChatWindow></ChatWindow>
      </template>
      <template v-else>
        <router-view/>
      </template>
    </div>
</template>

<script>
    "use strict";
    import ChatWindow from "@/components/chat-window2";
    import Cookie from "@/utils/cookie";

    export default {
        components: {ChatWindow},
        data() {
            return {}
        },
         
        mounted() {
          document.title = "法务智能机器人";

        },
      created() {
        const query = {... this.$route.query};
        const token = query.token;
        // 当携带token时刷新token并清掉地址栏token信息
        if (token) {
          delete(query["token"]);
          Cookie.setCookie("aitalk_token", token);
          history.replaceState(null, null, window.location.href.replace(/token=([^&]*)?&?/ig, ""));
        }
        const jumpTo = query.jumpTo;
        // 当携带jumpTo时，跳转到目标页面
        if(jumpTo){
          delete(query["jumpTo"]);
          this.$router.push({path: jumpTo, query: query});
        }
        const redirectAddressUrl = sessionStorage.getItem("redirectAddressUrl")
        if(redirectAddressUrl){
          //判断内存中是否有跳转地址，如果存在，则跳转到该地址，清空该地址，防止重复跳转
          sessionStorage.removeItem("redirectAddressUrl")
          location.replace(redirectAddressUrl)
        }
      }
    }
</script>

<style>

</style>
